//头部信息
ryAdmin.controller('Header', function($scope, $http, $location, $timeout, error, dom){
    // $scope.user     = Data('userinfo');
    $scope.user     = '';

    $scope.version='';
    //数据加载
    $scope.load_data    = function(){
        if(!$scope.user){
            var url     = config.prefix_url+'/Member/getInfo';
            $http.get(url).success(function(info){
                console.log(info);
                if(info.code != 1){
                    error.do_error(info);
                }else{
                    $scope.user     = info.data.info;
                    if($scope.user.nickname.length > 7){
                        $scope.user.nickname    = $scope.user.nickname.substr(0, 7)+'...';
                    }

                    $scope.version     = info.data.version;
                }
            });
        }
        

    }

    //退出登录
    $scope.logout   = function(){
        var url     = config.prefix_url+'/Public/logout';
        $http.get(url).success(function(info){
            if(info.code == 1){
                window.open('./login.html', '_self');
            }else{
                error.do_error(info);
            }
        });
    }

    //更改密码
    $scope.re_pass  = function(){
        var url     = config.prefix_url+'/User/submitPassword';
        var param   = {
            'old_pass'   : $scope.old_pass,
            'new_pass'   : $scope.new_pass,
            're_new_pass': $scope.re_new_pass
        };
        
        $http.post(url, param).success(function(info){
            console.log(info);
            if(info.code == 1){
                dom.do_alert('密码修改成功!');
                $('#modal-repass').modal('hide');
            }else{
                error.do_error(info);
            }
        });
    }

    //全屏
    $scope.full_screen  = function(){
        var WsShell = new ActiveXObject('WScript.Shell')
        WsShell.SendKeys('{F11}');
    }

    $scope.load_data();
});

//菜单栏导航控制
ryAdmin.controller('Menu', function($scope, $http, $rootScope, $location, usual, dom){
    usual.load_menus();

    $scope.collapse     = function(index){
        $('.s-list-group').collapse('hide');
        $('.s-list-group').eq(index).collapse('show');
    };

    $scope.open     = function(url){
        dom.open_url(url);

        $('.s-list-group > .list-group-item').each(function(){
            if($(this).data('url') == url){
                $(this).addClass('active');
            }else{
                $(this).removeClass('active');
            }
        });
    };
});
/**
 * 收入统计查询 - 收入统计
 * @time 2016年11月7日14:37:39
 * @author 竹晓玉  <zhuxiaoyu@iruiyou.com>
 */
ryAdmin.controller('IncomeForum',function($scope, $http, $rootScope, $location, error, dom, usual){
    $scope.test = "你好！我是收入统计的管家（控制器），请多多关照!O(∩_∩)O~";
    $scope.direction = false;


    /*搜索条件*/
    $scope.startDate = '';  //开始时间
    $scope.endDate = '';    //结束时间
    $scope.searchTime = 1;  //查询时间段
    $scope.nickname = '';   //用户
    $scope.dean = '';       //园长
    $scope.expand = '';     //教练
    $scope.teacher = '';     //老师
    $scope.course = '';     //课程


    $scope.startDateCharts = '';  //图表开始时间
    $scope.endDateCharts = '';    //图表结束时间


    /* 加载会员列表 */
    $scope.load_data = function (page) {
        var url = config.prefix_url + '/Money/get_list?&searchTime='+$scope.searchTime+'&startDate='+$scope.startDate+'&endDate='+$scope.endDate +'&nickname='+$scope.nickname
            +'&dean='+$scope.dean+'&expand='+$scope.expand+'&teacher='+$scope.teacher+'&course='+$scope.course+ '&p=' + page;
        console.log(url);
        $http.get(url).success(function (info) {
            console.log(info);
            if(info.code == 1){
                $scope.moneyList = info.data.list;
                $scope.pages     = info.data.pages;

                //设置分页事件
                dom.start_page($scope.load_data);
                dom.start_all_check();
            }else {
                $scope.moneyList = '';
                // dom.do_alert(info.data);
            }
        })
    }

    /* 条件搜索 */
    $scope.search_data = function (searchTime) {
        $scope.searchTime = 0;  //查询时间段
        $scope.load_data(1);
    }

    /* 切换查询时间 */
    $scope.change_load_data=function (type) {
        $scope.searchTime = type;
        $scope.startDate = '';  //开始时间
        $scope.endDate = '';    //结束时间
        $scope.nickname = '';   //用户
        $scope.dean = '';       //园长
        $scope.expand = '';     //教练
        $scope.teacher = '';     //老师
        $scope.course = '';     //课程

        $scope.load_data(1);

    }
    $scope.load_js   = function(){
        //使用日期控件
        $('.date').datetimepicker({
            format: 'yyyy-mm-dd',
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView:2,
            viewSelect: 2,
            forceParse: 0,
            showMeridian: 1
        });
    }

    /* 图表测试 */
    // 基于准备好的dom，初始化echarts实例
    var myChart1 = echarts.init(document.getElementById('main1'),'macarons');
    var myChart2 = echarts.init(document.getElementById('main2'),'macarons');
    var myChart3 = echarts.init(document.getElementById('main3'),'macarons');

    // 指定图表的配置项和数据
    $scope.init_echart = function (start,end) {
        if(start == undefined)
            start='';
        if(end == undefined)
            end='';
        var url = config.prefix_url+"/Money/getchartslist?&startime="+start+"&endtime="+end;
        console.log(url);
        $http.get(url).success(function (info) {
            console.log(info);
            if(info.code == 1){
                var option_income = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['流水', '最低', '中间']
                    },
                    toolbox: {
                        show: true,
                        orient: 'horizontal', // 布局方式，默认为水平布局，可选为：
                        // 'horizontal' ¦ 'vertical'
                        x: 'right', // 水平安放位置，默认为全图右对齐，可选为：
                        // 'center' ¦ 'left' ¦ 'right'
                        // ¦ {number}（x坐标，单位px）
                        y: 'top', // 垂直安放位置，默认为全图顶端，可选为：
                        // 'top' ¦ 'bottom' ¦ 'center'
                        // ¦ {number}（y坐标，单位px）
                        top:30,
                        backgroundColor: 'rgba(0,0,0,0)', // 工具箱背景颜色
                        borderColor: '#ccc', // 工具箱边框颜色
                        borderWidth: 0, // 工具箱边框线宽，单位px，默认为0（无边框）
                        padding: 5, // 工具箱内边距，单位px，默认各方向内边距为5，
                        showTitle: true,
                        feature: {
                            dataZoom: {
                                show: true,
                                title: {
                                    dataZoom: '区域缩放',
                                    dataZoomReset: '区域缩放-后退'
                                }
                            },
                            dataView: {
                                show: true,
                                title: '数据视图',
                                readOnly: true,
                                lang: ['数据视图', '关闭', '刷新'],
                                optionToContent: function(opt) {
                                    var axisData = opt.xAxis[0].data;
                                    var series = opt.series;
                                    var table = '<table style="width:100%;text-align:center"><tbody><tr>' +
                                        '<td>时间</td>' +
                                        '<td>' + series[0].name + '</td>' +
                                        '<td>' + series[1].name + '</td>' +
                                        '</tr>';
                                    for (var i = 0, l = axisData.length; i < l; i++) {
                                        table += '<tr>' +
                                            '<td>' + axisData[i] + '</td>' +
                                            '<td>' + series[0].data[i] + '</td>' +
                                            '<td>' + series[1].data[i] + '</td>' +
                                            '</tr>';
                                    }
                                    table += '</tbody></table>';
                                    return table;
                                }
                            },
                            magicType: {
                                show: true,
                                title: {
                                    line: '动态类型切换-折线图',
                                    bar: '动态类型切换-柱形图',
                                    stack: '动态类型切换-堆积',
                                    tiled: '动态类型切换-平铺'
                                },
                                type: ['line', 'bar', 'stack', 'tiled']
                            },
                            restore: {
                                show: true,
                                title: '还原',
                                color: 'black'
                            },
                            saveAsImage: {
                                show: true,
                                title: '保存为图片',
                                type: 'jpeg',
                                lang: ['点击本地保存']
                            }
                        }
                    },
                    calculable: true,
                    dataZoom: {
                        show: true,
                        realtime: true,
                        start: 20,
                        end: 80
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        label: {
                            normal: {
                                formatter: function(params) {
                                    console.log(params)
                                }
                            }
                        },
                        data: info.data.user_deduct.map(function (item) {
                            return item['time'];
                        }),
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                        name: '流水',
                        type: 'line',
                        data: info.data.user_deduct.map(function (item) {
                            return item['amount'];
                        }),
                    }],
                };

                var option_profit = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['利润', '最低', '中间']
                    },
                    toolbox: {
                        show: true,
                        orient: 'horizontal', // 布局方式，默认为水平布局，可选为：
                        // 'horizontal' ¦ 'vertical'
                        x: 'right', // 水平安放位置，默认为全图右对齐，可选为：
                        // 'center' ¦ 'left' ¦ 'right'
                        // ¦ {number}（x坐标，单位px）
                        y: 'top', // 垂直安放位置，默认为全图顶端，可选为：
                        // 'top' ¦ 'bottom' ¦ 'center'
                        // ¦ {number}（y坐标，单位px）
                        top:30,
                        backgroundColor: 'rgba(0,0,0,0)', // 工具箱背景颜色
                        borderColor: '#ccc', // 工具箱边框颜色
                        borderWidth: 0, // 工具箱边框线宽，单位px，默认为0（无边框）
                        padding: 5, // 工具箱内边距，单位px，默认各方向内边距为5，
                        showTitle: true,
                        feature: {
                            dataZoom: {
                                show: true,
                                title: {
                                    dataZoom: '区域缩放',
                                    dataZoomReset: '区域缩放-后退'
                                }
                            },
                            dataView: {
                                show: true,
                                title: '数据视图',
                                readOnly: true,
                                lang: ['数据视图', '关闭', '刷新'],
                                optionToContent: function(opt) {
                                    var axisData = opt.xAxis[0].data;
                                    var series = opt.series;
                                    var table = '<table style="width:100%;text-align:center"><tbody><tr>' +
                                        '<td>时间</td>' +
                                        '<td>' + series[0].name + '</td>' +
                                        '<td>' + series[1].name + '</td>' +
                                        '</tr>';
                                    for (var i = 0, l = axisData.length; i < l; i++) {
                                        table += '<tr>' +
                                            '<td>' + axisData[i] + '</td>' +
                                            '<td>' + series[0].data[i] + '</td>' +
                                            '<td>' + series[1].data[i] + '</td>' +
                                            '</tr>';
                                    }
                                    table += '</tbody></table>';
                                    return table;
                                }
                            },
                            magicType: {
                                show: true,
                                title: {
                                    line: '动态类型切换-折线图',
                                    bar: '动态类型切换-柱形图',
                                    stack: '动态类型切换-堆积',
                                    tiled: '动态类型切换-平铺'
                                },
                                type: ['line', 'bar', 'stack', 'tiled']
                            },
                            restore: {
                                show: true,
                                title: '还原',
                                color: 'black'
                            },
                            saveAsImage: {
                                show: true,
                                title: '保存为图片',
                                type: 'jpeg',
                                lang: ['点击本地保存']
                            }
                        }
                    },
                    calculable: true,
                    dataZoom: {
                        show: true,
                        realtime: true,
                        start: 20,
                        end: 80
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        label: {
                            normal: {
                                formatter: function(params) {
                                    console.log(params)
                                }
                            }
                        },
                        data: info.data.user_deduct.map(function (item) {
                            return item['time'];
                        }),
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                        name: '利润',
                        type: 'line',
                        data: info.data.user_deduct.map(function (item) {
                            return item['amount'];
                        }),
                    }],
                };

                var option_sell_course = {
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['售出数量', '最低', '中间']
                    },
                    toolbox: {
                        show: true,
                        orient: 'horizontal', // 布局方式，默认为水平布局，可选为：
                        // 'horizontal' ¦ 'vertical'
                        x: 'right', // 水平安放位置，默认为全图右对齐，可选为：
                        // 'center' ¦ 'left' ¦ 'right'
                        // ¦ {number}（x坐标，单位px）
                        y: 'top', // 垂直安放位置，默认为全图顶端，可选为：
                        // 'top' ¦ 'bottom' ¦ 'center'
                        // ¦ {number}（y坐标，单位px）
                        top:30,
                        backgroundColor: 'rgba(0,0,0,0)', // 工具箱背景颜色
                        borderColor: '#ccc', // 工具箱边框颜色
                        borderWidth: 0, // 工具箱边框线宽，单位px，默认为0（无边框）
                        padding: 5, // 工具箱内边距，单位px，默认各方向内边距为5，
                        showTitle: true,
                        feature: {
                            dataZoom: {
                                show: true,
                                title: {
                                    dataZoom: '区域缩放',
                                    dataZoomReset: '区域缩放-后退'
                                }
                            },
                            dataView: {
                                show: true,
                                title: '数据视图',
                                readOnly: true,
                                lang: ['数据视图', '关闭', '刷新'],
                                optionToContent: function(opt) {
                                    var axisData = opt.xAxis[0].data;
                                    var series = opt.series;
                                    var table = '<table style="width:100%;text-align:center"><tbody><tr>' +
                                        '<td>时间</td>' +
                                        '<td>' + series[0].name + '</td>' +
                                        '<td>' + series[1].name + '</td>' +
                                        '</tr>';
                                    for (var i = 0, l = axisData.length; i < l; i++) {
                                        table += '<tr>' +
                                            '<td>' + axisData[i] + '</td>' +
                                            '<td>' + series[0].data[i] + '</td>' +
                                            '<td>' + series[1].data[i] + '</td>' +
                                            '</tr>';
                                    }
                                    table += '</tbody></table>';
                                    return table;
                                }
                            },
                            magicType: {
                                show: true,
                                title: {
                                    line: '动态类型切换-折线图',
                                    bar: '动态类型切换-柱形图',
                                    stack: '动态类型切换-堆积',
                                    tiled: '动态类型切换-平铺'
                                },
                                type: ['line', 'bar', 'stack', 'tiled']
                            },
                            restore: {
                                show: true,
                                title: '还原',
                                color: 'black'
                            },
                            saveAsImage: {
                                show: true,
                                title: '保存为图片',
                                type: 'jpeg',
                                lang: ['点击本地保存']
                            }
                        }
                    },
                    calculable: true,
                    dataZoom: {
                        show: true,
                        realtime: true,
                        start: 20,
                        end: 80
                    },
                    xAxis: [{
                        type: 'category',
                        boundaryGap: false,
                        label: {
                            normal: {
                                formatter: function(params) {
                                    console.log(params)
                                }
                            }
                        },
                        data: info.data.sell_course.map(function (item) {
                            return item['time'];
                        }),
                    }],
                    yAxis: [{
                        type: 'value'
                    }],
                    series: [{
                        name: '售出数量',
                        type: 'line',
                        data: info.data.sell_course.map(function (item) {
                            return item['count'];
                        }),
                    }],
                };

                /*var option = {
                 tooltip: {
                 trigger: 'axis'
                 },
                 legend: {
                 data: ['最高', '最低', '中间']
                 },
                 toolbox: {
                 show: true,
                 orient: 'horizontal', // 布局方式，默认为水平布局，可选为：
                 // 'horizontal' ¦ 'vertical'
                 x: 'right', // 水平安放位置，默认为全图右对齐，可选为：
                 // 'center' ¦ 'left' ¦ 'right'
                 // ¦ {number}（x坐标，单位px）
                 y: 'top', // 垂直安放位置，默认为全图顶端，可选为：
                 // 'top' ¦ 'bottom' ¦ 'center'
                 // ¦ {number}（y坐标，单位px）
                 top:30,
                 backgroundColor: 'rgba(0,0,0,0)', // 工具箱背景颜色
                 borderColor: '#ccc', // 工具箱边框颜色
                 borderWidth: 0, // 工具箱边框线宽，单位px，默认为0（无边框）
                 padding: 5, // 工具箱内边距，单位px，默认各方向内边距为5，
                 showTitle: true,
                 feature: {
                 dataZoom: {
                 show: true,
                 title: {
                 dataZoom: '区域缩放',
                 dataZoomReset: '区域缩放-后退'
                 }
                 },
                 dataView: {
                 show: true,
                 title: '数据视图',
                 readOnly: true,
                 lang: ['数据视图', '关闭', '刷新'],
                 optionToContent: function(opt) {
                 var axisData = opt.xAxis[0].data;
                 var series = opt.series;
                 var table = '<table style="width:100%;text-align:center"><tbody><tr>' +
                 '<td>时间</td>' +
                 '<td>' + series[0].name + '</td>' +
                 '<td>' + series[1].name + '</td>' +
                 '</tr>';
                 for (var i = 0, l = axisData.length; i < l; i++) {
                 table += '<tr>' +
                 '<td>' + axisData[i] + '</td>' +
                 '<td>' + series[0].data[i] + '</td>' +
                 '<td>' + series[1].data[i] + '</td>' +
                 '</tr>';
                 }
                 table += '</tbody></table>';
                 return table;
                 }
                 },
                 magicType: {
                 show: true,
                 title: {
                 line: '动态类型切换-折线图',
                 bar: '动态类型切换-柱形图',
                 stack: '动态类型切换-堆积',
                 tiled: '动态类型切换-平铺'
                 },
                 type: ['line', 'bar', 'stack', 'tiled']
                 },
                 restore: {
                 show: true,
                 title: '还原',
                 color: 'black'
                 },
                 saveAsImage: {
                 show: true,
                 title: '保存为图片',
                 type: 'jpeg',
                 lang: ['点击本地保存']
                 }
                 }
                 },
                 calculable: true,
                 dataZoom: {
                 show: true,
                 realtime: true,
                 start: 20,
                 end: 80
                 },
                 xAxis: [{
                 type: 'category',
                 boundaryGap: false,
                 label: {
                 normal: {
                 formatter: function(params) {
                 console.log(params)
                 }
                 }
                 },
                 data: function() {
                 var list = [];
                 for (var i = 1; i <= 30; i++) {
                 list.push('2013-03-' + i);
                 }
                 return list;
                 }
                 }],
                 yAxis: [{
                 type: 'value'
                 }],
                 series: [{
                 name: '最高',
                 type: 'line',
                 data: function() {
                 var list = [];
                 for (var i = 1; i <= 30; i++) {
                 list.push(Math.round(Math.random() * 30));
                 }
                 return list;
                 }
                 }, {
                 name: '最低',
                 type: 'line',
                 data: function() {
                 var list = [];
                 for (var i = 1; i <= 30; i++) {
                 list.push(Math.round(Math.random() * 10));
                 }
                 return list;
                 }
                 }, {
                 name: '中间',
                 type: 'line',
                 data: function() {
                 var list = [];
                 for (var i = 1; i <= 30; i++) {
                 list.push(Math.round(Math.random() * 200));
                 }
                 return list;
                 }
                 }],
                 };*/

                // 使用刚指定的配置项和数据显示图表。
                myChart1.setOption(option_income);
                myChart2.setOption(option_profit);
                myChart3.setOption(option_sell_course);
            }else {
                dom.do_alert(info.data);
            }

        });
    }
    $scope.init_echart();
    $scope.load_js();
    $scope.load_data(1);
});
/**
 * 收入统计查询 - 平台收入
 * @time 2016年11月7日14:37:39
 * @author 竹晓玉  <zhuxiaoyu@iruiyou.com>
 */
ryAdmin.controller('IncomeCompany',function($scope, $http, $rootScope, $location, error, dom, usual){
    $scope.test = "你好！我是平台收入的管家（控制器），请多多关照!O(∩_∩)O~";
    $scope.direction = false;


    /*搜索条件*/
    $scope.startDate = '';  //开始时间
    $scope.endDate = '';    //结束时间
    $scope.searchTime = 1;  //查询时间段
    $scope.nickname = '';   //用户
    $scope.dean = '';       //园长
    $scope.expand = '';     //教练
    $scope.teacher = '';     //老师
    $scope.course = '';     //课程


    /* 加载会员列表 */
    $scope.load_data = function (page) {
        var url = config.prefix_url + '/Money/get_list?&searchTime='+$scope.searchTime+'&startDate='+$scope.startDate+'&endDate='+$scope.endDate +'&nickname='+$scope.nickname
            +'&dean='+$scope.dean+'&expand='+$scope.expand+'&teacher='+$scope.teacher+'&course='+$scope.course+ '&p=' + page;
        console.log(url);
        $http.get(url).success(function (info) {
            console.log(info);
            if(info.code == 1){
                $scope.moneyList = info.data.list;
            }else {
                $scope.moneyList = '';
                // dom.do_alert(info.data);
            }
        })
    }

    /* 条件搜索 */
    $scope.search_data = function (searchTime) {
        $scope.searchTime = 0;  //查询时间段
        $scope.load_data(1);
    }

    /* 切换查询时间 */
    $scope.change_load_data=function (type) {
        $scope.searchTime = type;
        $scope.startDate = '';  //开始时间
        $scope.endDate = '';    //结束时间
        $scope.nickname = '';   //用户
        $scope.dean = '';       //园长
        $scope.expand = '';     //教练
        $scope.teacher = '';     //老师
        $scope.course = '';     //课程

        $scope.load_data(1);

    }
    $scope.load_js   = function(){
        //使用日期控件
        $('.date').datetimepicker({
            format: 'yyyy-mm-dd',
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView:2,
            viewSelect: 2,
            forceParse: 0,
            showMeridian: 1
        });
    }
    $scope.load_js();
    $scope.load_data(1);
});


//推广员提现列表控制器
ryAdmin.controller('SellerIndex', function($scope, $http, $rootScope, $location, error, dom){
    $scope.load_js   = function(){
        //使用日期控件
        $('.date').datetimepicker({
            format: 'yyyy-mm-dd',
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView:2,
            viewSelect: 2,
            forceParse: 0,
            showMeridian: 1
        });
    }
    $scope.load_js();
    $scope.status='';
    $scope.startDate = '';  //开始时间
    $scope.endDate = '';    //结束时间
    //展示提现列表
    $scope.lists  = function(page){
        $('.nav-tabs li').removeClass('active');
        switch ($scope.status){
            case 2:
                $('.first').addClass('active');
                $scope.status = 2;
                break;
            case 1:
                $('.second').addClass('active');
                $scope.status = 1;
                break;
            case 0:
                $('.third').addClass('active');
                $scope.status = 0;
                break;
            default:
                $('.first').addClass('active');
                $scope.status = 2;
                break;
        }
        var url   =config.prefix_url +  '/Withdraw/Index?p='+page+'&status='+$scope.status+'&state=102'+'&starttime='+$scope.startDate+'&endtime='+$scope.endDate;
        console.log(url);
        $http.get(url).success(function(info){
            if(info.code == 1){
	 	console.log(info);
                $scope.applys     = info.data.applys;
                //设置分页事件
                $scope.pages    = info.data.pages;
                dom.start_page($scope.lists);
                dom.start_all_check();
            }
            else {
                error.do_error(info);
            }
        });
    }
    //初始化列表
    $scope.lists();
    //根据状态查询，切换签页
    $scope.changeIndex = function (status) {
        $scope.status = status;
        $scope.lists();
    }
    //审核
    $scope.applyid ='';
    $scope.first_check= function(id){
        $scope.applyid ='&id='+id;
        $(".modal-first").modal();
    }
    $scope.first_change_status= function(){
        var param  = '';
        $('[name = "id[]"]').each(function(index){
            if($(this).prop('checked')){
                param  += '&id[]='+$(this).val();
            }
        });
        $scope.applyid =param;
        $(".modal-first").modal();
    }
    $scope.second_check= function(id){
        $scope.applyid ='&id='+id;
        $(".modal-second").modal();
    }
    $scope.second_change_status= function(){
        var param  = '';
        $('[name = "id[]"]').each(function(index){
            if($(this).prop('checked')){
                param  += '&id[]='+$(this).val();
            }
        });
        $scope.applyid =param;
        $(".modal-second").modal();
    }

    $scope.content='';
    $scope.first_change_staus   = function(st){
        var url   =config.prefix_url +  '/Withdraw/firstchangestaus?status='+st+$scope.applyid+'&remark='+$scope.content;
        $http.get(url).success(function(info){
            if(info.code == 1){
                $scope.lists();
            }else{
                error.do_error(info.data);
            }
        });
    }
    $scope.second_change_staus   = function(st){
        var url   =config.prefix_url +  '/Withdraw/secondchangestaus?status='+st+$scope.applyid+'&remark='+$scope.content;
        $http.get(url).success(function(info){
            console.log(info);
            if(info.code == 1){
                $scope.lists();
            }else{
                error.do_error(info.data);
            }
        });
    }

    //数据导出
    $scope.out_list = function(){
        var url     = config.prefix_url +  '/Withdraw/outList?status='+$scope.status+'&state=102'+'&starttime='+$scope.startDate+'&endtime='+$scope.endDate;
        window.open(url, '_self');
    }

});

/**
 * 会员管理
 * @time 2016年11月7日14:37:39
 * @author 竹晓玉  <zhuxiaoyu@iruiyou.com>
 */
ryAdmin.controller('MemberIndex',function($scope, $http, $rootScope, $location, error, dom, usual){
    $scope.test = "你好！我是会员管理的管家（控制器），请多多关照!O(∩_∩)O~";
    $scope.member_index_menu = true;
    $scope.direction = false;
    $scope.tabsRole = '';
    $scope.menu = '';
    $scope.nickname = '';

    var role='';
    var page='';


    // $scope.crumbOptions = new Array();
    /*$scope.crumbOptions = [
     {"href": "http://www.baidu.com", "title" : "Home"},
     {"href": "http://www.sina.com", "title" : "Library"},
     {"href": "", "title" : "Data"}
     ];*/

    /* 加载会员列表 */
    $scope.load_data = function (page, role) {
	if(!role) role = '';
        $scope.member_index_menu = true;
        $scope.userinfo_id = '';
        $scope.menu = '';
        var url = config.prefix_url + '/Member/index?role_id='+ role + '&p=' + page + '&keyword=' + $scope.nickname;;
        console.log(url);
	$http.get(url).success(function (info) {
            if(info.code == 1){
                $scope.users = info.data.userList;
                $scope.roleNum = info.data.roleNum;
                $scope.pages     = info.data.pages;

                //设置分页事件
                dom.start_page($scope.load_data);
                dom.start_all_check();
            }else {
                error.do_error(info.data);
            }
        })
    }
    /* 切换角色 */
    $scope.change_data = function (page, role) {
        $scope.tabsRole = (role==undefined)?'':role;
        $scope.load_data(page, $scope.tabsRole);
    }

    /* 进入下级 */
    $scope.seeDetails = function(userId, roleId, nextall){
//	console.log($scope.nextall);
        if(nextall>0){
/*
         $(".breadcrumb").html('<li><a>全部</a></li>');*/
            /*$scope.crumbOptions.push({"url":"seeDetails("+userId+','+roleId+','+nextall+")","title":"aaaa"});
             $scope.crumbOptions.push({"url":"","title":"bbbb"});
             console.log($scope.crumbOptions);*/

            var url = config.prefix_url + '/Member/seeDetails?userId=' + userId + '&roleId=' + roleId + '&p=' + page;
		console.log(url);
            $http.get(url).success(function(info){
                console.log(info);
                if(info.code == 1){
                    $scope.member_index_menu = false;
                    $scope.users = info.data.userList;
                    $scope.menu = info.data.menu;
                    $scope.userinfo_id = $scope.menu.userinfo.id;
                    $scope.tabsRole = $scope.menu.userinfo.role_id;

                    $scope.pages     = info.data.pages;

                    //设置分页事件
                    dom.start_page($scope.seeDetails);
                    dom.start_all_check();
                }else{
                    error.do_error(info.data);
                }
            });
        }else {
            dom.do_alert('没有下级');
        }
    }
    $scope.seeDetailsQ = function(userId, roleId, nextall){
        $scope.userId = userId;
        $scope.roleId = roleId;
        $scope.nextall = nextall;
        $scope.seeDetails(1);
    }

    /* 排序 ->  1:ID  2:积分 3:累计金额  4:可提现金额  */
    $scope.toggle = function (type) {
        if ($scope.direction === false){
            $scope.direction = true;
            $scope.sortIcon="desc";
        }
        else{
            $scope.direction = false;
            $scope.sortIcon="asc";
        }
        // $scope.direction = true;
        $scope.sortName = type;

        if($scope.userinfo_id == undefined)
            $scope.userinfo_id = '';

        var url = config.prefix_url+'/Member/indexSort?&field_id='+ type + '&tabs_role=' + $scope.tabsRole + '&order=' + $scope.sortIcon + '&user_id=' +$scope.userinfo_id;
        console.log(url);
        $http.get(url).success(function (info) {
            if(info.code == 1){
                $scope.users = info.data.userList;
            }else {
                dom.do_alert(info.data);
            }
        });

    }


    /* 编辑会员信息 */
    $scope.change_user_info = function(userId, roleId, mobile){
        $scope.changeUserId = userId;
        $scope.role = roleId;
        $scope.user_mobile = mobile;

        $scope.roles = [
            {
                name:'园长',
                code:'101'
            },
            {
                name:'推销员（可提现）',
                code:'102'
            },
            {
                name:'推销员（可查看）',
                code:'103'
            },
            {
                name:'推销员（不可查看）',
                code:'104'
            },
            {
                name:'教师',
                code:'105'
            },
            {
                name:'家长',
                code:'106'
            }
        ];
        $('.change-user-role').modal('show');
    }

    /* 图表测试 */
    // 基于准备好的dom，初始化echarts实例
    /*var myChart = echarts.init(document.getElementById('main'),'macarons');

     // 指定图表的配置项和数据
     var option = {
     title: {
     text: 'ECharts 入门示例'
     },
     tooltip: {},
     legend: {
     data:['销量']
     },
     xAxis: {
     data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
     },
     yAxis: {},
     series: [{
     name: '销量',
     type: 'bar',
     data: [5, 20, 36, 10, 10, 20]
     }]
     };

     // 使用刚指定的配置项和数据显示图表。
     myChart.setOption(option);*/

    /* 保存会员信息 */
    $scope.save_userinfo = function (userId) {
        var url = config.prefix_url + '/Member/save_userinfo?&id=' + userId + '&role_id=' + $scope.role + '&mobile=' + $scope.user_mobile;
        console.log(url);
        $http.get(url).success(function (info) {
            console.log(info);
            if(info.code==1){
                $('.change-user-role').modal('hide');
                $scope.load_data();
                dom.do_alert(info.data);
            }else{
                dom.do_alert(info.data);
            }
        })
    }
    $scope.load_data();
});
